﻿
using Newtonsoft.Json;
using System;
using System.IO;

namespace MapleLeaf.Pay.Pay {
    public class HongshPayConfig {
        public HongshPayConfig() {

            ConfigFile = null;
            Load();
        }


        internal void Load() {
            if (ConfigFile == null) {
                ConfigFile = File.Open(GetType().Assembly.Location + ".save", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
            }
            else {
                ConfigFile.Position = 0L;
            }
            try {
                JsonConvert.PopulateObject(new StreamReader(ConfigFile).ReadToEnd(), this);
            }
            catch {

            }
        }


        public void Save() {
            ConfigFile.SetLength(0L);
            StreamWriter streamWriter = new StreamWriter(ConfigFile);
            streamWriter.Write(this.JsonEncode(Formatting.Indented));
            streamWriter.Flush();
        }
        private FileStream ConfigFile;
    }
}
